<template>
  <div class="page">
    <div class="pd-l bg-white bd-b">
      <input type="text" placeholder="请输入学生姓名" v-model="name"/>
    </div>
    <div class="fix-bottom">
      <notify-btn cls="ui btn primary no-rounder" :loading="isLoading" :disabled="!name" @hit="onCreate">完成</notify-btn>
    </div>
  </div>
</template>

<script>
import * as $group from '@/api/group'
import base from '@/mixins/base'
import NotifyBtn from '@/components/notify-btn'
import { mapGetters, mapActions } from 'vuex'

export default {
  mixins: [base],
  components: {NotifyBtn},
  data () {
    return {
      name: '',
      isLoading: false
    }
  },
  methods: {
    onPageShow () {
      let {name} = this.getParams()
      this.name = name
    },
    ...mapActions('group', [
      'getMyGroups'
    ]),
    async onCreate () {
      try {
        if (this.isLoading) return
        if (!this.name) return
        let {groupId} = this.getParams()
        this.isLoading = true
        await $group.modifyMemberInfo({groupId, name: this.name})
        this.isLoading = false
        this.$store.commit('UI_SET_TOAST_SUCCESS_MSG', '创建成功！')
        wx.navigateBack()
      } catch (e) {
        this.$debug({err: e})
      }
    }
  }
}
</script>

<style scoped lang="less">
</style>
